package com.example.database;

import android.content.Intent;
import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//        DBAdapter db = new DBAdapter(this);

//        db.open();
//        long id = db.insertContact("Wei-MengLee", "weimenglee@126.com");
//        id= db.insertContact("Mary Jakcson", "mary@126.com");
//        db.close();

//        Cursor c = db.getAllContacts();
//        if(c.moveToFirst()){
//            do{
//                displayContact(c);
//            }while (c.moveToNext());
//        }

//        Cursor c = db.getContact(1);
//        if(c.moveToFirst()){
//            displayContact(c);
//        } else {
//            Toast.makeText(this, "No contact found", Toast.LENGTH_LONG).show();
//        }

//        if(db.updateContact(1," Wei-Meng Lee", "weimenglee@gmail.com")){
//            Toast.makeText(this, "Update successful.", Toast.LENGTH_LONG).show();
//        } else {
//            Toast.makeText(this, "Update failed.", Toast.LENGTH_LONG).show();
//        }

//        if(db.deleteContact(1)){
//            Toast.makeText(this, "Delete successful.", Toast.LENGTH_LONG).show();
//        } else {
//            Toast.makeText(this, "Delete failed.", Toast.LENGTH_LONG).show();
//        }

//        db.close();;
    }

    public void displayContact(Cursor c){
        Toast.makeText(this, "id: "+ c.getString(0) + "\n" + "Name: " + c.getString(1) + "\n" + "Email: " + c.getString(2), Toast.LENGTH_LONG).show();
    }

    public void onClick(View v){
        startActivity(new Intent("com.example.database.DatabaseActivity"));
    }
}
